#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>

int main()
{
  //const char* message = "hello Linux!\n";
  //int fd = open("log.txt", O_RDONLY);
  //char buf[1024];
  //read(fd, buf, strlen(message));
  //printf("%s",buf);
  ////write(fd, message, strlen(message));
  //close(fd); // 关闭文件描述符指向的文件
  
  //int fd1 = open("fd1.txt", O_WRONLY|O_CREAT);
  //printf("%d\n", fd1);

  //int fd2 = open("fd2.txt", O_WRONLY|O_CREAT);
  //printf("%d\n", fd2);
  //int fd3 = open("fd3.txt", O_WRONLY|O_CREAT);
  //printf("%d\n", fd3);

  //pid_t pid = getpid();
  //while(1)
  //{
  //  sleep(1);
  //  printf("pid:%d\n", pid);
  //}
  
  //const char* msg = "hello!\n";
  //int fd = open("/dev/pts/1", O_WRONLY);
  //if (fd < 0) return -1;
  //else{

  //  while(1)
  //  {
  //    sleep(1);
  //    write(fd,msg, strlen(msg));
  //  }
  //}

  FILE* pf1 = fopen("fd1.txt", "w");
  printf("pf1:%d\n", pf1->_fileno);

  FILE* pf2 = fopen("fd2.txt", "w");
  printf("pf2:%d\n", pf2->_fileno);

  FILE* pf3 = fopen("fd3.txt", "w");
  printf("pf3:%d\n", pf3->_fileno);

  fclose(pf1);
  fclose(pf2);
  fclose(pf3);
  return 0;
}
